package perform.criterion;

public class And extends AbstractCriterion {

	private And(StringBuilder builder) {
		super(builder);
	}

	public static And create(Criterion criterion1, Criterion criterion2) {
		StringBuilder builder = new StringBuilder();
		builder.append(process(criterion1)).append(" and ")
				.append(process(criterion2));
		return new And(builder);
	}
	private static String process(Criterion criterion) {
		if (criterion instanceof Or) {
			return "( " + criterion.toString() + " )";
		} else {
			return criterion.toString();
		}
	}
	public And add(Criterion criterion) {
		builder.append(" and ").append(process(criterion));
		return this;
	}

}
